document.addEventListener('DOMContentLoaded', function() {
    // 重新验证电子签名
    document.querySelectorAll('.btn-verify').forEach(btn => {
        btn.addEventListener('click', function(e) {
            e.preventDefault();
            const contractId = window.location.pathname.split('/').pop();

            fetch(`/contract/verify-signature/${contractId}`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                }
            })
                .then(response => response.json())
                .then(data => {
                    if (data.valid) {
                        location.reload();
                    } else {
                        alert('验证失败：' + data.message);
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('验证过程中发生错误');
                });
        });
    });
});